const cloud = require('wx-server-sdk')

cloud.init({
	env: cloud.DYNAMIC_CURRENT_ENV,
})

exports.main = async (event) => {
	try {
		const { OPENID } = cloud.getWXContext()
		delete event.userInfo

		await cloud.database().collection('gn_user').doc(OPENID).update({
			data: event,
		})

		const { data } = await cloud.database().collection('gn_user').doc(OPENID).get()

		return {
			data,
			code: 0,
			msg: '更新成功',
		}
	} catch (err) {
		throw err
	}
}
